import { RemoteArgs, Remote } from '../types/Remote';
import { BaseRepository } from './BaseRepository'
import { relationalStore } from '@kit.ArkData';

export class RemoteRepository extends BaseRepository {

  async findAll(): Promise<Remote[]> {
    const result: Remote[] = []
    const resultSet = await this.db.querySql("select * from remote")
    const firstRow = resultSet.goToFirstRow();
    if (firstRow) {
      do {
        const remote: Remote = {
          id: resultSet.getLong(0),
          name: resultSet.getString(1),
          host: resultSet.getString(2),
        }
        result.push(remote)
      } while (resultSet.goToNextRow())
    }
    return result
  }

  async delete(id: number): Promise<number> {
    let predicates = new relationalStore.RdbPredicates("remote");
    predicates.equalTo("id", id);
    return await this.db.delete(predicates)
  }

  async create(remote: RemoteArgs): Promise<number> {
    return await this.db.insert("remote", remote)
  }




}